﻿<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        x:Class="BoilenEditor.SettingsWindow"
        Title="Boilen Editor Options"
        SizeToContent="WidthAndHeight"
        ShowInTaskbar="False">
    <Window.CommandBindings>
        <CommandBinding Command="Save"
                        Executed="SaveExecuted"
                        CanExecute="SaveCanExecute" />
        <CommandBinding Command="Close"
                        Executed="CancelExecuted" />
    </Window.CommandBindings>
    <Window.InputBindings>
        <KeyBinding Command="Close"
                    Gesture="Ctrl+W" />
    </Window.InputBindings>

    <DockPanel Margin="5">
        <StackPanel DockPanel.Dock="Bottom"
                    Orientation="Horizontal"
                    HorizontalAlignment="Right">
            <Button Style="{StaticResource DialogButton}"
                    IsDefault="True"
                    Content="_Save"
                    Command="Save" />
            <Button Style="{StaticResource DialogButton}"
                    IsCancel="True"
                    Content="_Cancel" />
        </StackPanel>

        <ItemsControl Name="settingsListBox_"
                      Grid.IsSharedSizeScope="True"
                      ItemsSource="{Binding Properties}"
                      Margin="5"
                      IsTabStop="False">
            <ItemsControl.ItemTemplate>
                <DataTemplate>
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto"
                                              SharedSizeGroup="Name" />
                            <ColumnDefinition Width="10" />
                            <ColumnDefinition Width="Auto"
                                              SharedSizeGroup="Value" />
                        </Grid.ColumnDefinitions>

                        <StackPanel Grid.Column="0"
                                    Orientation="Horizontal"
                                    HorizontalAlignment="Right">
                            <Label Content="{Binding Name, Mode=OneTime, Converter={StaticResource TitleCaseToLabel}}" />
                            <TextBlock Text="*"
                                       Foreground="DarkBlue"
                                       VerticalAlignment="Center"
                                       Visibility="{Binding IsDirty, Converter={StaticResource BooleanToHiddenVisibility}}" />
                        </StackPanel>

                        <TextBox Grid.Column="2"
                                 MinWidth="200"
                                 HorizontalAlignment="Stretch"
                                 ToolTip="{Binding RelativeSource={RelativeSource Self}, Path=(Validation.Errors)[0].Exception.InnerException}">
                            <TextBox.Text>
                                <Binding Path="SerializedValue"
                                         Mode="TwoWay"
                                         UpdateSourceTrigger="PropertyChanged">
                                    <Binding.ValidationRules>
                                        <ExceptionValidationRule ValidatesOnTargetUpdated="True" />
                                    </Binding.ValidationRules>
                                </Binding>
                            </TextBox.Text>
                        </TextBox>
                    </Grid>
                </DataTemplate>
            </ItemsControl.ItemTemplate>
        </ItemsControl>
    </DockPanel>
</Window>
